package dyy.zc.campuspay.ui.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import dyy.zc.campuspay.R;
import dyy.zc.campuspay.listener.OnItemClickListener;
import dyy.zc.campuspay.utils.Utils;

/**
 * Created by yyuand on 2017.3.15.
 */

public class PayStyleAdapter extends RecyclerView.Adapter<PayStyleAdapter.MyViewHolder> {
    private Context context;
    private int[] pics ;
    private String[] names;
    private OnItemClickListener onItemClickListener;
    public PayStyleAdapter(Context context,int[] pics,String[] names) {
        this.context = context;
        this.pics = pics;
        this.names = names;
    }

   public void setOnItemClickListener(OnItemClickListener onItemClickListener){
       this.onItemClickListener = onItemClickListener;
   }

    @Override
    public PayStyleAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        PayStyleAdapter.MyViewHolder holder = new PayStyleAdapter.MyViewHolder(
                LayoutInflater.from(context).inflate(R.layout.item_pay_style,parent,false),onItemClickListener);
        return holder;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        holder.ivPayPic.setImageResource(pics[position]);
        holder.tvPayStyle.setText(names[position]);
        Log.e("onBindViewHolder",names[position]+"");
        Log.e("onBindViewHolder",position+"");
    }

    @Override
    public int getItemCount() {
        return pics.length;
    }

    class MyViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
        private OnItemClickListener onItemClickListener;
        private ImageView ivPayPic;
        private TextView tvPayStyle;
        private ImageView ivGoto;

        public MyViewHolder(View itemView,OnItemClickListener onItemClickListener) {
            super(itemView);
            itemView.setOnClickListener(this);
            this.onItemClickListener = onItemClickListener;
            ivPayPic = Utils.findViewsById(itemView, R.id.iv_pay_pic);
            tvPayStyle = Utils.findViewsById(itemView,R.id.tv_pay_name);
            //ivGoto = Utils.findViewsById(itemView,R.id.goTo);

        }

        @Override
        public void onClick(View v) {
            if (onItemClickListener !=null){
                onItemClickListener.onItemClick(getAdapterPosition());
            }
        }

    }
}
